/********************************************************************************
* File Name:	mainwindow.cpp
* Description:	第3章 实例23：ProgressBar的实例
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProgressDialog>
#include <QThread>
//#include <windows.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    num=10;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnProgressBar_clicked()
{
    ui->progressBar->setRange(0,10);
    for(int i=1;i<=num;i++)
    {
        ui->progressBar->setValue(i);
        sleep(1);
    }
}

void MainWindow::on_btnProgressDialog_clicked()
{
    QProgressDialog *progressDialog = new QProgressDialog(this);
    QFont font("ZYSong18030",12);
    progressDialog->setFont(font);
    progressDialog->setWindowModality(Qt::WindowModal);
    progressDialog->setMinimumDuration(5);
    progressDialog->setWindowTitle("Please Waiting");
    progressDialog->setLabelText(tr("Copying..."));
    progressDialog->setCancelButtonText(tr("Cancel"));
    progressDialog->setRange(0,num);
    for(int i=1;i<=num;i++)
    {
        progressDialog->setValue(i);
        qApp->processEvents();
        sleep(1);
        if(progressDialog->wasCanceled())
            return;
    }
}
